<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:a="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:s="http://jboss.org/seam/faces"
	template="/WEB-INF/templates/backend/template.xhtml">
<ui:define name="content">
    <h1 class="title">编辑/添加产品</h1>
    
    <h:outputStylesheet>
        .top {
        vertical-align: top;
        }
 
        .info {
        height: 202px;
        overflow: auto;
        }
    </h:outputStylesheet>      
    
    <f:metadata>
        <f:viewParam name="productId" value="#{productManager.productId}"/>
        <s:viewAction action="#{productManager.wire}"/>
    </f:metadata>

<h:form>
    <h:panelGrid columns="2">
        <h:outputLabel for="goods">所属商品</h:outputLabel>
        <h:selectOneMenu value="#{productManager.instance.goods}" converter="goodsConverter">
            <f:selectItems
                itemLabel="#{_goods.name}" 
                itemValue="#{_goods}"
                value="#{goodsManager.resultList}"
                var="_goods"/>
        </h:selectOneMenu>        
        <h:outputLabel for="name">名称</h:outputLabel>
        <h:inputText value="#{productManager.instance.name}" id="name"/>
        <h:outputLabel for="code">编码</h:outputLabel>
        <h:inputText value="#{productManager.instance.code}" id="code"/>
        <h:outputLabel for="price">价格</h:outputLabel>
        <h:inputText value="#{productManager.instance.price}" id="price"/>        
        <h:outputLabel for="desc">描述</h:outputLabel>
        <h:inputTextarea value="#{productManager.instance.description}" cols="30" rows="5" id="desc"/>
        <h:outputLabel for="store">库存</h:outputLabel>
        <h:inputText value="#{productManager.instance.store}" size="5" id="store">
            <f:convertNumber pattern="###"/>
        </h:inputText>    
    </h:panelGrid>
    
    <h:panelGrid columns="2" columnClasses="top,top">
        <rich:fileUpload fileUploadListener="#{imageUpload.listener}"
                maxFilesQuantity="5"
                id="upload"
                immediateUpload="false"
                acceptedTypes="jpg,png,gif"
                ontyperejected="alert('只允许上传JPG, GIF,PNG图片');" 
                allowFlash="true" addControlLabel="添加" uploadControlLabel="上传" 
                clearAllControlLabel="清除所有" clearControlLabel="清除"
                cancelEntryControlLabel="取消"  stopControlLabel="停止" stopEntryControlLabel="停止" >
                <a:ajax event="filesubmit" execute="#{imageUpload.setImageFor('product')}"/>
                <a:ajax event="uploadcomplete" render="info"/>

                
        </rich:fileUpload>
        
        <h:panelGroup id="info">
            <rich:panel bodyClass="info">
                <f:facet name="header"><h:outputText value="图片信息" /></f:facet>
                <h:outputText value="还没有上传文件"  rendered="#{imageUpload.size==0}" />
                <rich:dataTable id="imageList"
                    var="_file"
                    value="#{imageUpload.productImages}"
                    rendered="#{not empty imageUpload.productImages}">
                    <h:column>
                        <f:facet name="header"><h:outputText value="图片" /></f:facet>
                        <rich:panel bodyClass="rich-laguna-panel-no-header">
                            <h:panelGrid columns="1">
                                <img src="/upload/#{_file.imageUrl}" width="80" height="80"/>                    
                            </h:panelGrid>
                        </rich:panel>             
                    </h:column>                    
                    </rich:dataTable>
                </rich:panel>
        </h:panelGroup>       
    </h:panelGrid>    
    
    <input type="hidden" name="productId" value="#{productManager.instance.id}"/>
    <h:inputHidden value="#{productManager.instance.id}"/>
    
    <div class="actionButtons">
        <h:commandButton action="#{productManager.save}" value="#{productManager.instance.id == null ? '添加' : '更新'}"/>
    </div>
    
</h:form>
	
</ui:define>
</ui:composition>
